# 设置最低 CMake 版本要求
cmake_minimum_required(VERSION 3.22.1)

# 设置项目名称
project(Cache)

# 设置 C++ 标准
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED True)

# 指定源文件目录下的所有 .cpp 文件
file(GLOB SOURCES "*.cpp")

# 设置目标可执行文件
add_executable(main ${SOURCES})

# 设置编译选项
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
    message(STATUS "Build type: Debug (with -g -O0)")
    target_compile_options(main PRIVATE -g -O0 -Wall -Wextra)
elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
    message(STATUS "Build type: Release (with -O2)")
    target_compile_options(main PRIVATE -O2 -DNDEBUG)
else()
    message(STATUS "Build type not set, defaulting to Debug")
    set(CMAKE_BUILD_TYPE Debug)
    target_compile_options(main PRIVATE -g -O0 -Wall -Wextra)
endif()

# 清理中间的 .o 文件
set_target_properties(main PROPERTIES CLEAN_DIRECT_OUTPUT 1)
